var iframe = function(){

    /**
     * 页面load
     */
    var build = function($title,$url,$param) {
        $width = $param.hasOwnProperty("width") ? $param['width'] : "100%";
        $w = $param.hasOwnProperty("w") ? $param['w'] : "";
        $height = $param.hasOwnProperty("height") ? $param['height'] : "";
        $footer = $param.hasOwnProperty("footer") ? $param['footer'] : 'block';
        $type = $param.hasOwnProperty("type") ? $param['type'] : '1';
        $class = $param.hasOwnProperty("function") ? $param['function'] : 'create';
        $left = '';
        if ($height == "") $height = ($(window).height()-150)+'px';
        if ($width == '100%') {
            $width = ($(window).width()-100)+'px';
            $left = "margin-left:50px;";
        }
        
        var max = '';
        if ($w != '') {
            var max = 'style="width:'+$w+'"';
        }
        if ($type == 1) {
            jQuery('body').prepend(
                '<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModal" data-backdrop="static">\n' +
                '    <div class="modal-dialog modal-lg" role="document" '+max+' style="width: '+$width+';'+$left+'">\n' +
                '        <div class="modal-content" style="width: '+$width+';">\n' +
                '            <div class="modal-header" style="">\n' +
                '                <h4 class="modal-title" id="exampleModalLabel">'+$title+'</h4>\n' +
                '                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>\n' +
                '            </div>\n' +
                '            <div class="modal-body" style="width: '+$width+';height: '+$height+';">\n' +
                '              <iframe src="'+$url+'" style="width: 100%;border: 0px;height: 100%;"></iframe>'+
                '            </div>\n' +
                '                <div class="modal-footer" style="display: '+$footer+';text-align: right;">\n' +
                '                  <button type="button" class="btn btn-default" data-dismiss="modal" style="border: 1px solid #ccc;color: #8e8e8e;">取消</button>\n' +
                '                  <button type="button" class="btn btn-primary" onclick="'+$class+'()">提交</button>\n' +
                '                </div>'+
                '        </div>\n' +
                '    </div>\n' +
                '</div>'
            );
        } else {
            if($.isPlainObject($url)) {
                var html = $url.prop("outerHTML");
            } else {
                var html = $url;
            }
            jQuery('body').prepend(
                '<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModal" data-backdrop="static">\n' +
                '    <div class="modal-dialog modal-lg" role="document">\n' +
                '        <div class="modal-content">\n' +
                '            <div class="modal-header" style="">\n' +
                '                <h4 class="modal-title" id="exampleModalLabel">'+$title+'</h4>\n' +
                '                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>\n' +
                '            </div>\n' +
                '            <div class="modal-body" style="width: '+$width+';height: '+$height+';">\n' +html+
                '            </div>\n' +
                '                <div class="modal-footer" style="display: '+$footer+';text-align: right;">\n' +
                '                  <button type="button" class="btn btn-default" data-dismiss="modal" style="border: 1px solid #ccc;color: #8e8e8e;">取消</button>\n' +
                '                  <button type="button" class="btn btn-primary" onclick="'+$class+'()">提交</button>\n' +
                '                </div>'+
                '        </div>\n' +
                '    </div>\n' +
                '</div>'
            );
        }

        $('#myModal').on('hide.bs.modal', function () {
            $('#myModal').remove();
        });
        // $('#myModal').on("show.bs.modal", function () {
        //     $(this).draggable();
        //     $(this).css("scroll", "false");
        // });
    };

    var open = function ($title,$url,$param={}) {
        build($title,$url,$param);
        $("#myModal").modal("show");
    };

    var close = function () {
        $("#myModal").modal("hide");
    };

    return {
        // 页面加载动画
        createIframe : function ($title,$url,$param={}) {
            open($title,$url,$param);
        }
    };
}();